package ssm.Controller;

import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import ssm.entity.book;
import ssm.entity.type;
import ssm.service.BookService;

import java.util.List;


/**
 * @author xiaochen
 */
@Controller
@RequestMapping("book")
public class BookController  {
    @Autowired
    private BookService bookService;

    @RequestMapping("list")
    public String findBook(Model model, @RequestParam(required = false,defaultValue = "1")int pageNum,  @RequestParam(required = false,defaultValue = "2")int pageSize){
        PageInfo<book> pageInfo=bookService.findAll(pageNum,pageSize);
        model.addAttribute("pageInfo",pageInfo);
        return "book/list";
    }
    @GetMapping("add")
    public String add(book book,Model model){
        List<type> types=bookService.findAlltypes();
        model.addAttribute("types",types);
        return "book/add";
    }
    @PostMapping("add")
    public String doAdd(book book,Model model){
        /*model.addAttribute("name",book);*/
        return "book/add";
    }
}
